package com.xcity.game.item;

import com.alibaba.fastjson.annotation.JSONField;

import naga.x.App;
import naga.x.game.template.TemplateService;

public class ItemInfo {

	protected int id; // 物品template id
	protected int count; // 物品数量
	
	@JSONField(serialize = false)
	protected ItemTemplate template;
	
	public static final ItemInfo[] EMPTY_ARRAY = new ItemInfo[0];
	
	public ItemInfo() {}
	
	public ItemInfo(int id, int count) {
		this.id = id;
		this.count = count;
	}
	
	public ItemInfo(ItemTemplate template, int count) {
		this.id = template.getId();
		this.count = count;
		this.template = template;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public ItemTemplate getTemplate() {
		return template != null ? template : (template = App.getApp().getServiceManager().get(TemplateService.class).get(ItemTemplate.class, id));
	}

	public void setTemplate(ItemTemplate template) {
		this.template = template;
	}
	
//	public String getName() {
//		return getTemplate().getName();
//	}
//	
//	public String getIcon() {
//		return getTemplate().getIcon();
//	}
//	
//	public String getDesc() {
//		return getTemplate().getDesc();
//	}

	public ItemInfo clone() {
		return new ItemInfo(id, count);
	}
	
	@Override
	public String toString() {
		return id + "=" + count;
	}
}
